<template>
  <div>
    <el-table :data="schedulelist" stripe style="width: 100%" @selection-change="handleSelectionChange"
      :selectable="selectable"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="hash.ep_ename" label="仪器设备名称" width="250"></el-table-column>
      <el-table-column prop="hash.scale" label="规格型号" width="150"></el-table-column>
      <el-table-column prop="hash.managenum" label="管理编号" width="150"></el-table-column>
      <el-table-column prop="hash.traceability" label="溯源方式"></el-table-column>
      <el-table-column prop="hash.verifiy_company" label="检定/校准单位" width="250"></el-table-column>
      <el-table-column prop="hash.verifiy_person" label="检定员"></el-table-column>

      <el-table-column prop="hash.verifiy_round" label="检定/校准周期"></el-table-column>
      <el-table-column prop="hash.verifiytime" label="计划检定/校准日期" width="100"></el-table-column>
      <el-table-column prop="hash.realtime" label="实际检定/校准时间" width="100"></el-table-column>
      <el-table-column prop="hash.nextverifiytime" label="下次检定/校准日期" width="100"></el-table-column>
      <el-table-column label="检定状态" width="150">
        <template slot-scope="scope">
          <span v-if="scope.row.hash.status=='0'">未提交证书</span>
          <span v-else-if="scope.row.hash.status=='1'">已提交证书</span>
          <span v-else>无需确认</span>
        </template>
      </el-table-column>
      <div v-if="ismanager==1">
        <el-table-column label="已确认" width="150">
          <template slot-scope="scope" v-if="scope.row.hash.status!='0'">
            {{scope.row.hash.yqrnum}} / {{scope.row.hash.personnum}}
          </template>
        </el-table-column>
        <el-table-column label="已审核" width="150">
          <template slot-scope="scope" v-if="scope.row.hash.status!='0'">
            {{scope.row.hash.yshnum}} / {{scope.row.hash.personnum}}
          </template>
        </el-table-column>
        <el-table-column label="已批准" width="150">
          <template slot-scope="scope" v-if="scope.row.hash.status!='0'">
            {{scope.row.hash.ypznum}} / {{scope.row.hash.personnum}}
          </template>
        </el-table-column>
      </div>
      <el-table-column prop="hash.shr_kcl" label="已确认" width="100" v-if="ismanager==3"></el-table-column>
      <el-table-column prop="hash.pzr_kcl" label="已审核" width="100" v-if="ismanager==4"></el-table-column>

      <el-table-column label="操作" width="400" fixed="right">
        <template slot-scope="scope">
          <div>
            <el-button size="mini" type="primary" @click="showdia(1,scope.row)" v-if="usertype==1&&scope.row.hash.status=='0'">提交检定</el-button>
            <el-button size="mini" type="primary" @click="showdia(0,scope.row.hash.id)" v-if="usertype==1&&scope.row.hash.status=='1'">确认记录</el-button>
            <el-button size="mini" type="primary" @click="showsubcheck(scope.row)" v-if="usertype==1&&(scope.row.hash.status=='1'||scope.row.hash.status=='2')">检定证书</el-button>

            <el-button size="mini" type="danger" @click="resubmitcheck(scope.row)"
              v-if="usertype==1&&(scope.row.hash.status=='1'||scope.row.hash.status=='2')"
            >重新检定</el-button>
            <el-button size="mini" type="danger" @click="nocheck(scope.row)"
              v-if="usertype==1&&scope.row.hash.status=='1'"
            >无需确认</el-button>
            <el-button size="mini" type="primary" @click="showdia(2,scope.row.hash.id)" v-else-if="usertype==2">结果确认</el-button>
            <el-button size="mini" type="primary" @click="showdia(3,scope.row.hash.id)" v-else-if="usertype==3">审核</el-button>
            <el-button size="mini" type="primary" @click="showdia(4,scope.row.hash.id)" v-else-if="usertype==4">审批</el-button>
          </div>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @current-change="handleCurrentChange"
      :currentPage.sync="pagobj.currentPage3"
      :pageSize="pagobj.pagesize"
      layout="total, prev, pager, next"
      :total="pagobj.total"
      style="margin:20px 0;text-align:center"
    >
    </el-pagination>

    <div v-if="schedulelist.length>0">
      <submitcheck v-if="step1" :item1="item1"></submitcheck>
      <submitrecord v-if="step0" :approvetable="approvetable0"></submitrecord>
      <confirmcheck v-if="step2" :item2="item2" :childmethod2="childmethod2"></confirmcheck>
      <docheck v-if="step3" :shtable="shtable" :childmethod2="childmethod2"></docheck>
      <approvecheck v-if="step4" :approvetable="approvetable" :childmethod2="childmethod2"></approvecheck>
    </div>

    <!-- //设备检定管理员模块 -->
    <el-dialog
      title="查看检定报告"
      :visible.sync="showcheckreport"
      width="50%"
    >
      <p>检定/校准费用： {{verifiy_fee}}</p>
      <el-table
        :data="checkreportlist"
        stripe
        style="width: 100%"
      >
        <el-table-column
          type="index"
          width="50"
        >
        </el-table-column>
        <el-table-column
          prop="hash.certnum"
          label="证书编号"
        >
        </el-table-column>
        <el-table-column label="修正因子">
          <template slot-scope="scope">
            <div v-html="scope.row.hash.factor">{{scope.row.hash.factor}}</div>
          </template>
        </el-table-column>
        <el-table-column label="查看附件">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="checkfj(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="查看附件"
        :visible.sync="showcheckreport2"
        appendToBody
      >
        <el-table
          :data="fileArr"
          stripe
          style="width: 100%"
        >
          <el-table-column
            type="index"
            width="50"
          >
          </el-table-column>
          <el-table-column
            prop="hash.filename"
            label="附件名称"
          >
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <a :href="scope.row.hash.fileurl" target="_blank" download="">下 载</a>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </el-dialog>

    <!-- //设备检定使用人模块 -->
    <el-dialog
      title="结果确认"
      :visible.sync="showcofirm"
      width="50%"
    >
      <el-table
        :data="cofirmtable"
        stripe
        style="width: 100%"
      >
        <el-table-column
          type="index"
          width="50"
        >
        </el-table-column>
        <el-table-column
          prop="hash.certnum"
          label="证书编号"
        >
        </el-table-column>
        <el-table-column label="修正因子">
          <template slot-scope="scope">
            <div v-html="scope.row.hash.factor">{{scope.row.hash.factor}}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="hash.upload_time"
          label="提交时间"
        >
        </el-table-column>
        <el-table-column
          prop="hash.verifiy_project"
          label="检测项目"
        >
        </el-table-column>
        <el-table-column
          label="量值"
        >
          <template slot-scope="scope">
            <div v-html="scope.row.hash.measurement">{{scope.row.hash.measurement}}</div>
          </template>
        </el-table-column>
        <el-table-column
          label="状态"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.hash.status=='-1'" style="color:red">被驳回</span>
            <span v-if="scope.row.hash.status=='0'">确认人未提交</span>
            <span v-if="scope.row.hash.status=='1'">确认人已提交</span>
            <span v-if="scope.row.hash.status=='2'">审核人批准</span>
            <span v-if="scope.row.hash.status=='3'">批准人批准</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="hash.confirm_personname"
          label="确认人"
        >
        </el-table-column>
        <el-table-column label="查看附件">
          <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="checkfj2(scope.row)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">

            <el-button size="mini" type="primary" @click="showconfirmrecord(scope.row)">确认记录</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="查看附件"
        :visible.sync="showcofirm2"
        appendToBody
      >
        <el-table
          :data="fileArr2"
          stripe
          style="width: 100%"
        >
          <el-table-column
            type="index"
            width="50"
          >
          </el-table-column>
          <el-table-column
            prop="hash.filename"
            label="附件名称"
          >
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <a :href="scope.row.hash.fileurl" target="_blank" download="">下 载</a>
            </template>
          </el-table-column>
        </el-table>
      </el-dialog>
    </el-dialog>


  </div>
</template>

<script>
import submitcheck from '~/components/apparatus/eqschedule/submitcheck.vue';
import submitrecord from '~/components/apparatus/eqschedule/submitrecord.vue';
import confirmcheck from '~/components/apparatus/eqschedule/confirmcheck.vue';
import docheck from '~/components/apparatus/eqschedule/docheck.vue';
import approvecheck from '~/components/apparatus/eqschedule/approvecheck.vue';

export default {
  components: {
    submitcheck,
    submitrecord,
    confirmcheck,
    docheck,
    approvecheck,
  },
  data() {
    return {
      ts: this.newStore(),
      showcheckreport: false,
      showcheckreport2: false,
      dialogVisible: false,
      showcofirm: false,
      showcofirm2: false,
      showsh: false,
      showsh2: false,
      step0: false,
      step1: false,
      step2: false,
      step3: false,
      step4: false,
      item1: {},
      item2: {},
      verifiy_fee: '',
      checkreportlist: [],
      fileArr: [],
      fileArr2: [],
      cofirmtable: [],
      shtable: [],
      approvetable: [],
      approvetable0: [],
    };
  },
  props: {
    schedulelist: {
      type: Array,
      required: true,
    },
    ismanager: Number,
    usertype: {
      type: Number,
      required: true,
    },
    choosedp: Array,
    pagobj: {
      type: Object,
      required: true,
    },
  },
  methods: {
    childmethod2() {
      this.$parent.getschedulelist();
    },
    nocheck(item) {
      this.$confirm('确认提交无需确认?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = {
            handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7A49CA81F795657FFE351DE64652882229',
            id: item.hash.id,
          };
          this.spost(this.ts, '/mainservlet', req).then(() => {
            this.$message({
              type: 'success',
              message: '提交成功！',
            });
            this.$parent.getschedulelist();
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
    resubmitcheck(item) {
      this.$confirm('确认重新检定?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = {
            handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7A0A8887D0F3DB3B51351DE64652882229',
            id: item.hash.id,
          };
          this.spost(this.ts, '/mainservlet', req).then(() => {
            this.$message({
              type: 'success',
              message: '重新检定提交成功！',
            });
            this.$parent.getschedulelist();
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
    showconfirmrecord(item) {
      this.item2 = item;
      this.reload('step2');
    },
    checkfj(item) {
      console.log(item);
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C51F0C438E24ECDA3C',
        id: item.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.fileArr = ts.d.data.operation1;
        this.showcheckreport2 = true;
      });
    },
    checkfj2(item) {
      console.log(item);
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C51F0C438E24ECDA3C',
        id: item.hash.cid,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.fileArr2 = ts.d.data.operation1;
        this.showcofirm2 = true;
      });
    },
    showsubcheck(item) {
      console.log(item);
      const req = {
        handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C5CD3A43E9777C4E90',
        id: item.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        this.verifiy_fee = ts.d.data.operation1[0].hash.verifiy_fee;
        this.checkreportlist = ts.d.data.operation2;
        this.showcheckreport = true;
      });
    },
    selectable(row) {
      if (row.hash.status == '0') {
        return true;
      }
      return false;
    },
    showdia(type, item) {
      if (type == 0) {
        const req = {
          handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C53BF12CE79649F82DF9BE89CF91227798',
          id: item,
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          this.approvetable0 = ts.d.data.operation1;
        });
        this.reload('step0');
      } else if (type == 1) {
        this.item1 = item;
        this.reload('step1');
      } else if (type == 2) {
        const req = {
          handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C53BF12CE79649F82DF9BE89CF91227798',
          id: item,
          syrid: localStorage.getItem('pid'),
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          this.cofirmtable = ts.d.data.operation1;
          this.showcofirm = true;
        });
      } else if (type == 3) {
        const req = {
          handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C53BF12CE79649F82DF9BE89CF91227798',
          id: item,
          shrorgid: localStorage.getItem('dept'),
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          this.shtable = ts.d.data.operation1;
          console.log(this.shtable,'this.shtable')
        });
        this.reload('step3');
      } else {
        const req = {
          handle: 'DD5D108B99FC12B782127AB5198E65DA50B1E3C352635A7AF1087BC5FD3B20C53BF12CE79649F82DF9BE89CF91227798',
          id: item,
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          this.approvetable = ts.d.data.operation1;
        });
        this.reload('step4');
      }
    },
    reload(vifname) {
      this[vifname] = false;
      this.$nextTick(() => {
        this[vifname] = true;
      });
    },
    handleCurrentChange() {
      this.$parent.getschedulelist();
    },
    handleSelectionChange(val) {
      this.$emit('update:choosedp', val);
    },
  },
};
</script>

<style>
</style>
